import java.awt.Graphics;
import java.awt.Point;

import javax.swing.JOptionPane;

public class Circle extends Node
{
	int radius;
	Point center = new Point();
	String label;
	
	public Circle(String name, int x, int y, int r)
	{
		super(name);
		center.setLocation(x, y);
		radius = r;
		this.label = name;
	}
	
	void setLocation(Point p)
	{
		center.setLocation(p);
	}
	void draw(Graphics g)
	{
		g.drawOval(
				center.x-radius, 
				center.y-radius, 
				radius*2, radius*2);
		if(label != null)
			g.drawString(label, center.x, center.y);
//		for(int i = 0; i < edges.size(); ++i)
//		{
//			edges.get(i).draw(g);
//		}
		for (Edge e : edges) {
			e.draw(g);
		}
	}
	
	public boolean contains(Point p)
	{
		double dx = p.x-center.x;
		double dy = p.y-center.y;
//		// checking distance
//		double dist = Math.sqrt(dx*dx+dy*dy);
//		return dist <= radius*radius;
		// checking quadrance
		double dist = dx*dx+dy*dy;
		return dist <= radius*radius;
//		// checking manahttan distance
//		double dist = dx+dy;
//		return dist <= radius;
	}
	
	public Point edgeToward(Point p)
	{
		int dx = p.x-center.x;
		int dy = p.y-center.y;
		double dist = Math.sqrt(dx*dx+dy*dy);
		dx = (int)(dx * radius/dist);
		dy = (int)(dy * radius/dist);
		Point result = new Point(center.x+dx, center.y+dy);
		return result;
	}
	
	public String setLabel()
	{
	   String response = JOptionPane.showInputDialog(null,
			   null, "Node Label",
			   JOptionPane.QUESTION_MESSAGE);
	   if(response != null)
	   {
		   label = response;
	   }
	   return response;
	}
}
